<template>
  <div class="xqxdiv" v-if="ifsetting">
    <el-card style="width: 380px; margin-right: 20px; position: relative">
      <template #header>
        <div class="card-header">
          <span>镶嵌线配置</span>
        </div>
      </template>
      <div style="position: absolute; top: 10px; right: 10px">
        <el-button type="" size="default" @click="saveXQX()"> 保存 </el-button>
      </div>
      <el-descriptions class="margin-top" title="" :column="1" border>
        <el-descriptions-item :label-class-name="'dsl'">
          <template #label>
            <div class="cell-item" style="">边框颜色</div>
          </template>
          <el-color-picker show-alpha color-format="hex" v-model="commonsetting.data.xiangqianxianjson.bordercolor1" />
          {{commonsetting.data.xiangqianxianjson.bordercolor1}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">填充颜色</div>
          </template>
          <el-color-picker show-alpha color-format="hex" v-model="commonsetting.data.xiangqianxianjson.fillcolor1" />
          {{commonsetting.data.xiangqianxianjson.fillcolor1}}
        </el-descriptions-item>
        <el-descriptions-item :label-class-name="'dsl'">
          <template #label>
            <div class="cell-item" style="">边框宽度</div>
          </template>
          <el-input v-model="commonsetting.data.xiangqianxianjson.borderwidth" style="" placeholder="" />
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">透明度</div>
          </template>

          <div class="frcc">
            <el-input-number v-model="commonsetting.data.xiangqianxianjson.toumingdu" :min="1" :max="10">
            </el-input-number>
            %
          </div>


          <!-- <el-input-number v-model="num" :min="1" :max="10">
          </el-input-number> -->
        </el-descriptions-item>
      </el-descriptions>
    </el-card>
    <el-card style="width: 380px; margin-right: 20px">
      <template #header>
        <div class="card-header">
          <span>图层配置</span>
        </div>
      </template>
      <el-descriptions class="margin-top" title="" :column="1" border>
        <el-descriptions-item :label-class-name="'dsl'">
          <template #label>
            <div class="cell-item" style="">底图图层</div>
          </template>
        </el-descriptions-item>
        <el-descriptions-item :label-class-name="'dsl'">
          <template #label>
            <div class="cell-item" style="">注记图层</div>
          </template>
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">图层</div>
          </template>
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">图层1</div>
          </template>
        </el-descriptions-item>
      </el-descriptions>
    </el-card>
  </div>
</template>
<script setup>
import { reactive, ref, onMounted } from "vue";
import {ElMessage} from "element-plus"

import { useLocalStorage } from '@vueuse/core';

import { apiList } from "@/api/apiList";

import { Base64 } from 'js-base64'

import _ from 'lodash'


let ifsetting = ref(false)


let commonsettingtmp = {
  xiangqianxianjson: {
  bordercolor1: "#9F2214",
  fillcolor1: "#580443",
  borderwidth: "1",
  toumingdu: "10",
  },

  earthjson: {

  },

  tablejson: {

  }

}

let commonsetting = reactive({data:{}})

function saveXQX(){

  let params = {
    lineStyle: ''
  }
  params.lineStyle = Base64.encode(JSON.stringify(commonsetting.data))
  apiList.setlineType(params).then(res => {
    ElMessage.success('保存配置成功')
  })

}

onMounted(() => {
  loadData()
})

function loadData() {
  ifsetting.value = false
  apiList.getlineType().then(res => {
    let nowjson = {}
    try {
      nowjson = JSON.parse(Base64.decode(res.data))
    } catch (error) {
      nowjson = commonsettingtmp
    }
    if (!_.has(nowjson, 'xiangqianxianjson')) {
      nowjson = commonsettingtmp
    }
    commonsetting.data = nowjson
    ifsetting.value = true
  })
}

</script>
<style lang="scss">
.dsl {
  width: 150px;
}
.xqxdiv {
  padding: 20px;
  display: flex;
  flex-direction: row;
  // position: relative;
}
</style>
